#!/bin/bash

set -e


#当前路径
function print_meun(){
	echo -e "*******************************************"
	echo -e "* Welcome to download OpenHarmony Code    *"
	echo -e "* Please Choice OpenHarmony SDK:	   *"
	echo -e "* OpenHarmony Version             	   *"
	echo -e "*   OpenHarmony master       	prese 1.1  *"
	echo -e "*   OpenHarmony-3.2-beta2    	press 1.2  *"
	echo -e "*   OpenHarmony-3.2-beta2-merge press 1.3 *"
	echo -e "*   OpenHarmony-3.2-release  	press 1.4  *"
	echo -e "*******************************************"
read -p "输入下载版本:" A

}

function create_directory()
{
	if [ ! -e ${version} ]; then
		mkdir ${version}
		cd ${version}
	elif [ ! -e "${version}"_tmp ]; then
		mkdir "${version}"_tmp
		cd "${version}"_tmp
	else
		rm "${version}"_tmp -rf
		mkdir "${version}"_tmp
		cd "${version}"_tmp
	fi
}

function print_download()
{
	echo "you have been download OpenHarmony OpenHarmony-3.2-Release code"
	echo "url       : https://gitee.com/openharmony/manifest.git"
	echo "branch    : ${version}"
	echo "xml_name  : ${xmlname}"
	echo "code_path : $(pwd)"
	echo "init   cmd: repo init -u ${gitcode} -b ${version} -m ${xmlname} --no-repo-verify"
	echo "sync   cmd: repo sync -c"
	echo "lfs    cmd: repo forall -c 'git lfs pull'"
	echo "set_br cmd: repo ${version} --all"

}

function choose_version()
{
	while :
	do
		if [ "$A" = "1.1" ]; then
#			echo "下载1.1"
			version="master"
			gitcode="https://gitee.com/openharmony/manifest.git"
			break

		elif [ "$A" = "1.2" ]; then
#			echo "下载1.2"
			gitcode="https://gitee.com/openharmony/manifest"
			version="OpenHarmony-3.2-beta2"
			break
		
		elif [ "$A" = "1.3" ]; then
#			echo "下载1.3"
			gitcode="https://gitee.com/openharmony/manifest"
			version="OpenHarmony-3.2-beta2-Merge"
			xmlname="thead_develop.xml"
			break
		elif [ "$A" = "1.4" ]; then
#			echo "下载1.4"
			version="OpenHarmony-3.2-Release"
			gitcode="https://gitee.com/openharmony/manifest"
			xmlname="default.xml"
			break
		else
			echo "product is not in product list, please recheck!!!"
			print_meun
		fi

	done
	create_directory
	print_download

}



function main()
{
	print_meun
	choose_version

}

main
